package com.example.sync.handler.impl;

import com.example.mq.loader.SysMQLoader;
import com.example.sync.handler.impl.wrap.RabbitMQMessageWrap;
import com.example.sync.po.SysASyncJob;
import com.example.utils.SerializableUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/*
 * @className: SysRabbitMQMessageSendHandler
 * @author: chentao
 * @date: 2025/3/25 下午4:57
 * @Version: 1.0
 * @description:
 */
@Service
public class SysRabbitMQMessageSendHandler extends SysAbstractHandler {

    public static final String TYPE = "mq_send_rabbitmq";

    @Resource
    private SysMQLoader sysMQLoader;

    @Override
    public String getType() {
        return TYPE;
    }

    @Override
    public void handle(SysASyncJob sysASyncJob) throws Exception {
        RabbitMQMessageWrap rabbitMQMessageWrap = (RabbitMQMessageWrap) SerializableUtils.deserializeFromString(sysASyncJob.getTargetContent(), RabbitMQMessageWrap.class);
        this.sysMQLoader.getSysMQFactory().publish(rabbitMQMessageWrap.getExchange(), rabbitMQMessageWrap.getRoutingKey(), rabbitMQMessageWrap.getContent());
    }
}
